﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Anata;
using Anata.TableForm;
using Anata.AnataServerDataSetTableAdapters;

namespace Anata
{
    /// <summary>
    /// Main form for system interface
    /// </summary>
    /// 
    public partial class AdminDialogueForm : Form
    {
        private DataSet ds = new DataSet();
        private DataTable dt = new DataTable();
        private TreeNode administratif; private TreeNode karyawan; private TreeNode cabang; private TreeNode asetstok; private TreeNode transaksi; private TreeNode lainnya;
        private TreeNode node;
        private TreeNode node00; private TreeNode node01; private TreeNode node02; private TreeNode node03; private TreeNode node04;
        private TreeNode node05; private TreeNode node06; private TreeNode node07; private TreeNode node08; private TreeNode node09;
        private TreeNode node10; private TreeNode node11; private TreeNode node12; private TreeNode node13; private TreeNode node14;
        private TreeNode node15; private TreeNode node16; private TreeNode node17; private TreeNode node18; private TreeNode node19;
        private TreeNode node20; private TreeNode node21; private TreeNode node22; private TreeNode node23; private TreeNode node24;
        private TreeNode node25;

        /// <summary>
        /// Main form construktor</summary>
        /// <remarks>
        /// Form containing all table from the Anata database </remarks>
        public AdminDialogueForm()
        {
            InitializeComponent();
            splitContainer1.Panel1.Enabled = false;
            logOutToolStripMenuItem.Enabled = false;
        }

        /// <summary>
        /// Main form constructor with refresh compability
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AdminDialogueForm_Load(object sender, EventArgs e)
        {
            DataTableCollection dt = anatadbserver.Tables;

            // Administratif 
            node00 = new TreeNode("User"); node00.Tag = dt[00].ToString();
            node18 = new TreeNode("Role"); node18.Tag = dt[18].ToString();
            node19 = new TreeNode("Log Server"); node19.Tag = dt[19].ToString();

            // Karyawan
            node11 = new TreeNode("Konsumen"); node11.Tag = dt[11].ToString();
            node08 = new TreeNode("Karyawan"); node08.Tag = dt[08].ToString();
            node09 = new TreeNode("Keahlian"); node09.Tag = dt[09].ToString();
            node15 = new TreeNode("Preferensi Karyawan"); node15.Tag = dt[15].ToString();

            // Transaksi
            node22 = new TreeNode("Transaksi"); node22.Tag = dt[22].ToString();
            node23 = new TreeNode("Transaksi Layanan"); node23.Tag = dt[23].ToString();
            node24 = new TreeNode("Transaksi Pembayaran"); node24.Tag = dt[24].ToString();
            node25 = new TreeNode("Transaksi Produk"); node25.Tag = dt[25].ToString();
            node14 = new TreeNode("Metode Pembayaran"); node14.Tag = dt[14].ToString();
            node17 = new TreeNode("Promo"); node17.Tag = dt[17].ToString();
            node04 = new TreeNode("Free Gift"); node04.Tag = dt[04].ToString();

            // Cabang
            node03 = new TreeNode("Cabang"); node03.Tag = dt[03].ToString();
            node12 = new TreeNode("Layanan"); node12.Tag = dt[12].ToString();
            node10 = new TreeNode("Komisi Layanan"); node10.Tag = dt[10].ToString();
            node13 = new TreeNode("Layanan Cabang"); node13.Tag = dt[13].ToString();
            node16 = new TreeNode("Produk Cabang"); node16.Tag = dt[16].ToString();

            // Aset & Stok
            node02 = new TreeNode("Aset"); node02.Tag = dt[02].ToString();
            node06 = new TreeNode("Jenis Aset"); node06.Tag = dt[06].ToString();
            node21 = new TreeNode("Stok"); node21.Tag = dt[21].ToString();
            node07 = new TreeNode("Jenis Stok"); node07.Tag = dt[07].ToString();

            // Lainnya
            node01 = new TreeNode("Agama"); node01.Tag = dt[01].ToString();
            node05 = new TreeNode("Golongan Darah"); node05.Tag = dt[05].ToString();
            node20 = new TreeNode("Status"); node20.Tag = dt[20].ToString();
        }

        /// <summary>
        /// Add Record Button click function
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e) { showTableForm(); }

        /// <summary>
        /// Edit Record Button click function
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {

            Int32 selectedCellCount = dataGridView1.GetCellCount(DataGridViewElementStates.Selected);

            if (selectedCellCount > 0)
            {
                if (dataGridView1.AreAllCellsSelected(true)) MessageBox.Show("Harap pilih row yang akan di edit.", "Selected Cells");
                else showEditTableForm();
            }
        }

        /// <summary>
        /// Delete Record Button click function
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button3_Click(object sender, EventArgs e) { deleteRow(); }

        /// <summary>
        /// Main form button initilization
        /// </summary>
        public void initializeButton()
        {
            button1.Enabled = true; button2.Enabled = true; button3.Enabled = true;

            if (Equals(node.Tag, "server_log") || Equals(node.Tag, "transaksi") || Equals(node.Tag, "transaksi_layanan") || Equals(node.Tag, "transaksi_pembayaran") || Equals(node.Tag, "transaksi_produk"))
            {
                button1.Enabled = false; button2.Enabled = false; button3.Enabled = false;
            }
        }

        /// <summary>
        /// Refresh view of associated tabel in datagrid
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            node = treeView1.SelectedNode;
            initializeButton();

            if (node.Text.Equals("Tabel"))
            {
                toolStripStatusLabel1.Text = "Ready.";
                dataGridView1.DataSource = null;
            }
            else toolStripStatusLabel1.Text = "Tabel " + node.Text + " dipilih.";

            try
            {
                if (Equals(node.Tag, "_user"))
                {
                    _userTableAdapter f = new _userTableAdapter();
                    AnataServerDataSet._userDataTable tabel = new AnataServerDataSet._userDataTable();
                    f.Fill(tabel); dataGridView1.DataSource = tabel;
                    tabel.Columns[0].ColumnName = "ID Karyawan ";
                    tabel.Columns[1].ColumnName = "Username ";
                    tabel.Columns[2].ColumnName = "Password ";
                    tabel.Columns[3].ColumnName = "ID Role ";
                }
                else if (Equals(node.Tag, "agama"))
                {
                    agamaTableAdapter f = new agamaTableAdapter();
                    AnataServerDataSet.agamaDataTable tabel = new AnataServerDataSet.agamaDataTable();
                    f.Fill(tabel); dataGridView1.DataSource = tabel;
                    tabel.Columns[0].ColumnName = "ID ";
                    tabel.Columns[1].ColumnName = "Nama ";
                }
                else if (Equals(node.Tag, "aset"))
                {
                    asetTableAdapter f = new asetTableAdapter();
                    AnataServerDataSet.asetDataTable tabel = new AnataServerDataSet.asetDataTable();
                    f.Fill(tabel); dataGridView1.DataSource = tabel;
                    tabel.Columns[0].ColumnName = "ID ";
                    tabel.Columns[1].ColumnName = "ID Cabang ";
                    tabel.Columns[2].ColumnName = "ID Jenis Aset ";
                    tabel.Columns[3].ColumnName = "Nama ";
                    tabel.Columns[4].ColumnName = "Harga Jual ";
                    tabel.Columns[5].ColumnName = "Harga Beli ";
                    tabel.Columns[6].ColumnName = "Mortisasi ";
                    tabel.Columns[7].ColumnName = "Jumlah ";
                    tabel.Columns[8].ColumnName = "Tgl Jual ";
                    tabel.Columns[9].ColumnName = "Tgl Beli ";
                }
                else if (Equals(node.Tag, "cabang"))
                {
                    cabangTableAdapter f = new cabangTableAdapter();
                    AnataServerDataSet.cabangDataTable tabel = new AnataServerDataSet.cabangDataTable();
                    f.Fill(tabel); dataGridView1.DataSource = tabel;
                    tabel.Columns[0].ColumnName = "ID ";
                    tabel.Columns[1].ColumnName = "Nama ";
                    tabel.Columns[2].ColumnName = "Alamat ";
                    tabel.Columns[3].ColumnName = "Stok? ";
                }
                else if (Equals(node.Tag, "free_gift"))
                {
                    free_giftTableAdapter f = new free_giftTableAdapter();
                    AnataServerDataSet.free_giftDataTable tabel = new AnataServerDataSet.free_giftDataTable();
                    f.Fill(tabel); dataGridView1.DataSource = tabel;
                    tabel.Columns[0].ColumnName = "ID ";
                    tabel.Columns[1].ColumnName = "ID Layanan Cabang ";
                    tabel.Columns[2].ColumnName = "Nama ";
                    tabel.Columns[3].ColumnName = "Kuantitas ";
                    tabel.Columns[4].ColumnName = "Tidak Aktif? ";
                }
                else if (Equals(node.Tag, "golongan_darah"))
                {
                    golongan_darahTableAdapter f = new golongan_darahTableAdapter();
                    AnataServerDataSet.golongan_darahDataTable tabel = new AnataServerDataSet.golongan_darahDataTable();
                    f.Fill(tabel); dataGridView1.DataSource = tabel;
                    tabel.Columns[0].ColumnName = "ID ";
                    tabel.Columns[1].ColumnName = "Nama ";
                }
                else if (Equals(node.Tag, "jenis_aset"))
                {
                    jenis_asetTableAdapter f = new jenis_asetTableAdapter();
                    AnataServerDataSet.jenis_asetDataTable tabel = new AnataServerDataSet.jenis_asetDataTable();
                    f.Fill(tabel); dataGridView1.DataSource = tabel;
                    tabel.Columns[0].ColumnName = "ID ";
                    tabel.Columns[1].ColumnName = "Nama ";
                }
                else if (Equals(node.Tag, "jenis_stok"))
                {
                    jenis_stokTableAdapter f = new jenis_stokTableAdapter();
                    AnataServerDataSet.jenis_stokDataTable tabel = new AnataServerDataSet.jenis_stokDataTable();
                    f.Fill(tabel); dataGridView1.DataSource = tabel;
                    tabel.Columns[0].ColumnName = "ID ";
                    tabel.Columns[1].ColumnName = "Nama ";
                }
                else if (Equals(node.Tag, "karyawan"))
                {
                    karyawanTableAdapter f = new karyawanTableAdapter();
                    AnataServerDataSet.karyawanDataTable tabel = new AnataServerDataSet.karyawanDataTable();
                    f.Fill(tabel); dataGridView1.DataSource = tabel;
                    tabel.Columns[00].ColumnName = "ID ";
                    tabel.Columns[01].ColumnName = "Nama ";
                    tabel.Columns[02].ColumnName = "ID Cabang ";
                    tabel.Columns[03].ColumnName = "Alamat ";
                    tabel.Columns[04].ColumnName = "No Telp ";
                    tabel.Columns[05].ColumnName = "No KTP ";
                    tabel.Columns[06].ColumnName = "Pria? ";
                    tabel.Columns[07].ColumnName = "Tgl Lahir ";
                    tabel.Columns[08].ColumnName = "ID Status ";
                    tabel.Columns[09].ColumnName = "ID Agama ";
                    tabel.Columns[10].ColumnName = "ID Golongan Darah ";
                    tabel.Columns[11].ColumnName = "Tgl Masuk ";
                    tabel.Columns[12].ColumnName = "Tgl Keluar ";
                }
                else if (Equals(node.Tag, "keahlian"))
                {
                    keahlianTableAdapter f = new keahlianTableAdapter();
                    AnataServerDataSet.keahlianDataTable tabel = new AnataServerDataSet.keahlianDataTable();
                    f.Fill(tabel); dataGridView1.DataSource = tabel;
                    tabel.Columns[0].ColumnName = "ID ";
                    tabel.Columns[1].ColumnName = "ID Karyawan ";
                    tabel.Columns[2].ColumnName = "ID Layanan ";
                }
                else if (Equals(node.Tag, "komisi_layanan"))
                {
                    komisi_layananTableAdapter f = new komisi_layananTableAdapter();
                    AnataServerDataSet.komisi_layananDataTable tabel = new AnataServerDataSet.komisi_layananDataTable();
                    f.Fill(tabel); dataGridView1.DataSource = tabel;
                    tabel.Columns[0].ColumnName = "ID ";
                    tabel.Columns[1].ColumnName = "ID Cabang ";
                    tabel.Columns[2].ColumnName = "ID Layanan ";
                    tabel.Columns[3].ColumnName = "Komisi ";
                }
                else if (Equals(node.Tag, "konsumen"))
                {
                    konsumenTableAdapter f = new konsumenTableAdapter();
                    AnataServerDataSet.konsumenDataTable tabel = new AnataServerDataSet.konsumenDataTable();
                    f.Fill(tabel); dataGridView1.DataSource = tabel;
                    tabel.Columns[0].ColumnName = "ID ";
                    tabel.Columns[1].ColumnName = "Nama ";
                    tabel.Columns[2].ColumnName = "Nomor ";
                    tabel.Columns[3].ColumnName = "Alamat ";
                    tabel.Columns[4].ColumnName = "No Telp ";
                    tabel.Columns[5].ColumnName = "Pria? ";
                    tabel.Columns[6].ColumnName = "Tgl Lahir ";
                    tabel.Columns[7].ColumnName = "Usia (thn.)";
                }
                else if (Equals(node.Tag, "layanan"))
                {
                    layananTableAdapter f = new layananTableAdapter();
                    AnataServerDataSet.layananDataTable tabel = new AnataServerDataSet.layananDataTable();
                    f.Fill(tabel); dataGridView1.DataSource = tabel;
                    tabel.Columns[0].ColumnName = "ID ";
                    tabel.Columns[1].ColumnName = "Nama ";
                    tabel.Columns[2].ColumnName = "Durasi (mnt.) ";
                }
                else if (Equals(node.Tag, "layanan_cabang"))
                {
                    layanan_cabangTableAdapter f = new layanan_cabangTableAdapter();
                    AnataServerDataSet.layanan_cabangDataTable tabel = new AnataServerDataSet.layanan_cabangDataTable();
                    f.Fill(tabel); dataGridView1.DataSource = tabel;
                    tabel.Columns[0].ColumnName = "ID ";
                    tabel.Columns[1].ColumnName = "ID Layanan ";
                    tabel.Columns[2].ColumnName = "ID Cabang ";
                    tabel.Columns[3].ColumnName = "Harga ";
                }
                else if (Equals(node.Tag, "metode_pembayaran"))
                {
                    metode_pembayaranTableAdapter f = new metode_pembayaranTableAdapter();
                    AnataServerDataSet.metode_pembayaranDataTable tabel = new AnataServerDataSet.metode_pembayaranDataTable();
                    f.Fill(tabel); dataGridView1.DataSource = tabel;
                    tabel.Columns[0].ColumnName = "ID ";
                    tabel.Columns[1].ColumnName = "Nama ";
                }
                else if (Equals(node.Tag, "preferensi_karyawan"))
                {
                    preferensi_karyawanTableAdapter f = new preferensi_karyawanTableAdapter();
                    AnataServerDataSet.preferensi_karyawanDataTable tabel = new AnataServerDataSet.preferensi_karyawanDataTable();
                    f.Fill(tabel); dataGridView1.DataSource = tabel;
                    tabel.Columns[0].ColumnName = "ID ";
                    tabel.Columns[1].ColumnName = "ID Konsumen ";
                    tabel.Columns[2].ColumnName = "ID Keahlian ";
                }
                else if (Equals(node.Tag, "produk_cabang"))
                {
                    produk_cabangTableAdapter f = new produk_cabangTableAdapter();
                    AnataServerDataSet.produk_cabangDataTable tabel = new AnataServerDataSet.produk_cabangDataTable();
                    f.Fill(tabel); dataGridView1.DataSource = tabel;
                    tabel.Columns[0].ColumnName = "ID ";
                    tabel.Columns[1].ColumnName = "ID Cabang ";
                    tabel.Columns[2].ColumnName = "Harga ";
                    tabel.Columns[3].ColumnName = "Komisi ";
                }
                else if (Equals(node.Tag, "promo"))
                {
                    promoTableAdapter f = new promoTableAdapter();
                    AnataServerDataSet.promoDataTable tabel = new AnataServerDataSet.promoDataTable();
                    f.Fill(tabel); dataGridView1.DataSource = tabel;
                    tabel.Columns[0].ColumnName = "ID ";
                    tabel.Columns[1].ColumnName = "ID Layanan Cabang ";
                    tabel.Columns[2].ColumnName = "Nama ";
                    tabel.Columns[3].ColumnName = "Tgl Mulai ";
                    tabel.Columns[4].ColumnName = "Tgl Akhir ";
                    tabel.Columns[5].ColumnName = "Persentase ";
                    tabel.Columns[6].ColumnName = "Nominal ";
                    tabel.Columns[7].ColumnName = "Pemotongan ";
                    tabel.Columns[8].ColumnName = "Syarat ";
                }
                else if (Equals(node.Tag, "role"))
                {
                    roleTableAdapter f = new roleTableAdapter();
                    AnataServerDataSet.roleDataTable tabel = new AnataServerDataSet.roleDataTable();
                    f.Fill(tabel); dataGridView1.DataSource = tabel;
                    tabel.Columns[0].ColumnName = "ID ";
                    tabel.Columns[1].ColumnName = "Nama ";
                }
                else if (Equals(node.Tag, "server_log"))
                {
                    server_logTableAdapter f = new server_logTableAdapter();
                    AnataServerDataSet.server_logDataTable tabel = new AnataServerDataSet.server_logDataTable();
                    f.Fill(tabel); dataGridView1.DataSource = tabel;
                    tabel.Columns[0].ColumnName = "ID ";
                    tabel.Columns[1].ColumnName = "ID User ";
                    tabel.Columns[2].ColumnName = "ID Jenis Query ";
                    tabel.Columns[3].ColumnName = "Tabel ";
                    tabel.Columns[4].ColumnName = "RowID ";
                    tabel.Columns[5].ColumnName = "Field ";
                    tabel.Columns[6].ColumnName = "Nilai Lama ";
                    tabel.Columns[7].ColumnName = "Nilai Baru ";
                    tabel.Columns[8].ColumnName = "Timestamp ";
                }
                else if (Equals(node.Tag, "status"))
                {
                    statusTableAdapter f = new statusTableAdapter();
                    AnataServerDataSet.statusDataTable tabel = new AnataServerDataSet.statusDataTable();
                    f.Fill(tabel); dataGridView1.DataSource = tabel;
                    tabel.Columns[0].ColumnName = "ID ";
                    tabel.Columns[1].ColumnName = "Nama ";
                }
                else if (Equals(node.Tag, "stok"))
                {
                    stokTableAdapter f = new stokTableAdapter();
                    AnataServerDataSet.stokDataTable tabel = new AnataServerDataSet.stokDataTable();
                    f.Fill(tabel); dataGridView1.DataSource = tabel;
                    tabel.Columns[0].ColumnName = "ID ";
                    tabel.Columns[1].ColumnName = "ID Jenis Stok ";
                    tabel.Columns[2].ColumnName = "Nama ";
                    tabel.Columns[3].ColumnName = "Jumlah Beli ";
                    tabel.Columns[4].ColumnName = "Jumlah Aktual ";
                    tabel.Columns[5].ColumnName = "Harga Beli ";
                    tabel.Columns[6].ColumnName = "Tgl Beli ";
                    tabel.Columns[7].ColumnName = "Tgl Kadaluarsa ";
                    tabel.Columns[8].ColumnName = "Catatan ";
                    tabel.Columns[9].ColumnName = "ID Cabang ";
                }
                else if (Equals(node.Tag, "transaksi"))
                {
                    transaksiTableAdapter f = new transaksiTableAdapter();
                    AnataServerDataSet.transaksiDataTable tabel = new AnataServerDataSet.transaksiDataTable();
                    f.Fill(tabel); dataGridView1.DataSource = tabel;
                    tabel.Columns[0].ColumnName = "ID ";
                    tabel.Columns[1].ColumnName = "ID Cabang ";
                    tabel.Columns[2].ColumnName = "ID Konsumen ";
                    tabel.Columns[3].ColumnName = "Tgl Masuk ";
                    tabel.Columns[4].ColumnName = "Tgl Keluar ";
                    tabel.Columns[5].ColumnName = "Total Harga ";
                    tabel.Columns[6].ColumnName = "Nominal ";
                    tabel.Columns[7].ColumnName = "Persentase ";
                    tabel.Columns[8].ColumnName = "Correction ";
                }
                else if (Equals(node.Tag, "transaksi_layanan"))
                {
                    transaksi_layananTableAdapter f = new transaksi_layananTableAdapter();
                    AnataServerDataSet.transaksi_layananDataTable tabel = new AnataServerDataSet.transaksi_layananDataTable();
                    f.Fill(tabel); dataGridView1.DataSource = tabel;
                    tabel.Columns[0].ColumnName = "ID ";
                    tabel.Columns[1].ColumnName = "ID Transaksi ";
                    tabel.Columns[2].ColumnName = "ID Karyawan ";
                    tabel.Columns[3].ColumnName = "ID Layanan Cabang ";
                    tabel.Columns[4].ColumnName = "Harga ";
                    tabel.Columns[5].ColumnName = "Kulitas ";
                    tabel.Columns[6].ColumnName = "ID Promo ";
                    tabel.Columns[7].ColumnName = "ID Free Gift ";
                }
                else if (Equals(node.Tag, "transaksi_pembayaran"))
                {
                    transaksi_pembayaranTableAdapter f = new transaksi_pembayaranTableAdapter();
                    AnataServerDataSet.transaksi_pembayaranDataTable tabel = new AnataServerDataSet.transaksi_pembayaranDataTable();
                    f.Fill(tabel); dataGridView1.DataSource = tabel;
                    tabel.Columns[0].ColumnName = "ID ";
                    tabel.Columns[1].ColumnName = "ID Transaksi ";
                    tabel.Columns[2].ColumnName = "Metode Pembayaran ";
                    tabel.Columns[3].ColumnName = "Jumlah ";
                }
                else if (Equals(node.Tag, "transaksi_produk"))
                {
                    transaksi_produkTableAdapter f = new transaksi_produkTableAdapter();
                    AnataServerDataSet.transaksi_produkDataTable tabel = new AnataServerDataSet.transaksi_produkDataTable();
                    f.Fill(tabel); dataGridView1.DataSource = tabel;
                    tabel.Columns[0].ColumnName = "ID ";
                    tabel.Columns[1].ColumnName = "ID Transaksi ";
                    tabel.Columns[2].ColumnName = "ID Karyawan ";
                    tabel.Columns[3].ColumnName = "ID Produk Cabang ";
                    tabel.Columns[4].ColumnName = "Jumlah ";
                    tabel.Columns[5].ColumnName = "Harga ";
                    tabel.Columns[6].ColumnName = "Persentase ";
                    tabel.Columns[7].ColumnName = "Nominal ";
                }

            }
            catch (Exception msg) { MessageBox.Show(msg + "Koneksi ke database tidak ditemukan, perbaiki koneksi melalui Database Setting."); }
        }

        /// <summary>
        /// Handle showing table in datagrid
        /// </summary>
        public void showTableForm()
        {
            node = treeView1.SelectedNode;

            if (Equals(node.Tag, "_user")) { UserForm f = new UserForm(this); f.Show(); }
            else if (Equals(node.Tag, "agama")) { AgamaForm f = new AgamaForm(this); f.Show(); }
            else if (Equals(node.Tag, "aset")) { AsetForm f = new AsetForm(this); f.Show(); }
            else if (Equals(node.Tag, "cabang")) { CabangForm f = new CabangForm(this); f.Show(); }
            else if (Equals(node.Tag, "free_gift")) { FreeGiftForm f = new FreeGiftForm(this); f.Show(); }
            else if (Equals(node.Tag, "golongan_darah")) { GolonganDarahForm f = new GolonganDarahForm(this); f.Show(); }
            else if (Equals(node.Tag, "jenis_aset")) { JAsetForm f = new JAsetForm(this); f.Show(); }
            else if (Equals(node.Tag, "jenis_stok")) { JStokForm f = new JStokForm(this); f.Show(); }
            else if (Equals(node.Tag, "karyawan")) { KaryawanForm f = new KaryawanForm(this); f.Show(); }
            else if (Equals(node.Tag, "keahlian")) { KeahlianForm f = new KeahlianForm(this); f.Show(); }
            else if (Equals(node.Tag, "komisi_layanan")) { KomisiLayananForm f = new KomisiLayananForm(this); f.Show(); }
            else if (Equals(node.Tag, "konsumen")) { KonsumenForm f = new KonsumenForm(this); f.Show(); }
            else if (Equals(node.Tag, "layanan")) { LayananForm f = new LayananForm(this); f.Show(); }
            else if (Equals(node.Tag, "layanan_cabang")) { LayananCabangForm f = new LayananCabangForm(this); f.Show(); }
            else if (Equals(node.Tag, "metode_pembayaran")) { MetodeBayarForm f = new MetodeBayarForm(this); f.Show(); }
            else if (Equals(node.Tag, "preferensi_karyawan")) { PreferensiKaryawanForm f = new PreferensiKaryawanForm(this); f.Show(); }
            else if (Equals(node.Tag, "produk_cabang")) { ProdukCabangForm f = new ProdukCabangForm(this); f.Show(); }
            else if (Equals(node.Tag, "promo")) { PromoForm f = new PromoForm(this); f.Show(); }
            else if (Equals(node.Tag, "role")) { RoleForm f = new RoleForm(this); f.Show(); }
            else if (Equals(node.Tag, "server_log")) { MessageBox.Show("Fitur belum diimplementasikan."); }
            else if (Equals(node.Tag, "status")) { StatusForm f = new StatusForm(this); f.Show(); }
            else if (Equals(node.Tag, "stok")) { StokForm f = new StokForm(this); f.Show(); }
            else if (Equals(node.Tag, "transaksi")) { MessageBox.Show("Fitur belum diimplementasikan."); }
            else if (Equals(node.Tag, "transaksi_layanan")) { MessageBox.Show("Fitur belum diimplementasikan."); }
            else if (Equals(node.Tag, "transaksi_pembayaran")) { MessageBox.Show("Fitur belum diimplementasikan."); }
            else if (Equals(node.Tag, "transaksi_produk")) { MessageBox.Show("Fitur belum diimplementasikan."); }
            else { MessageBox.Show("Pilih tabel terlebih dahulu."); }
        }

        public void showEditTableForm()
        {
            node = treeView1.SelectedNode;

            if (Equals(node.Tag, "_user")) { UserForm f = new UserForm(this, dataGridView1); f.Show(); }
            else if (Equals(node.Tag, "agama")) { AgamaForm f = new AgamaForm(this, dataGridView1); f.Show(); }
            else if (Equals(node.Tag, "aset")) { AsetForm f = new AsetForm(this, dataGridView1); f.Show(); }
            else if (Equals(node.Tag, "cabang")) { CabangForm f = new CabangForm(this, dataGridView1); f.Show(); }
            else if (Equals(node.Tag, "free_gift")) { FreeGiftForm f = new FreeGiftForm(this, dataGridView1); f.Show(); }
            else if (Equals(node.Tag, "golongan_darah")) { GolonganDarahForm f = new GolonganDarahForm(this, dataGridView1); f.Show(); }
            else if (Equals(node.Tag, "jenis_aset")) { JAsetForm f = new JAsetForm(this, dataGridView1); f.Show(); }
            else if (Equals(node.Tag, "jenis_stok")) { JStokForm f = new JStokForm(this, dataGridView1); f.Show(); }
            else if (Equals(node.Tag, "karyawan")) { KaryawanForm f = new KaryawanForm(this, dataGridView1); f.Show(); }
            else if (Equals(node.Tag, "keahlian")) { KeahlianForm f = new KeahlianForm(this, dataGridView1); f.Show(); }
            else if (Equals(node.Tag, "komisi_layanan")) { KomisiLayananForm f = new KomisiLayananForm(this, dataGridView1); f.Show(); }
            else if (Equals(node.Tag, "konsumen")) { KonsumenForm f = new KonsumenForm(this, dataGridView1); f.Show(); }
            else if (Equals(node.Tag, "layanan")) { LayananForm f = new LayananForm(this, dataGridView1); f.Show(); }
            else if (Equals(node.Tag, "layanan_cabang")) { LayananCabangForm f = new LayananCabangForm(this, dataGridView1); f.Show(); }
            else if (Equals(node.Tag, "metode_pembayaran")) { MetodeBayarForm f = new MetodeBayarForm(this, dataGridView1); f.Show(); }
            else if (Equals(node.Tag, "preferensi_karyawan")) { PreferensiKaryawanForm f = new PreferensiKaryawanForm(this, dataGridView1); f.Show(); }
            else if (Equals(node.Tag, "produk_cabang")) { ProdukCabangForm f = new ProdukCabangForm(this, dataGridView1); f.Show(); }
            else if (Equals(node.Tag, "promo")) { PromoForm f = new PromoForm(this, dataGridView1); f.Show(); }
            else if (Equals(node.Tag, "role")) { RoleForm f = new RoleForm(this, dataGridView1); f.Show(); }
            else if (Equals(node.Tag, "server_log")) { MessageBox.Show("Fitur belum diimplementasikan."); }
            else if (Equals(node.Tag, "status")) { StatusForm f = new StatusForm(this, dataGridView1); f.Show(); }
            else if (Equals(node.Tag, "stok")) { StokForm f = new StokForm(this, dataGridView1); f.Show(); }
            else if (Equals(node.Tag, "transaksi")) { MessageBox.Show("Fitur belum diimplementasikan."); }
            else if (Equals(node.Tag, "transaksi_layanan")) { MessageBox.Show("Fitur belum diimplementasikan."); }
            else if (Equals(node.Tag, "transaksi_pembayaran")) { MessageBox.Show("Fitur belum diimplementasikan."); }
            else if (Equals(node.Tag, "transaksi_produk")) { MessageBox.Show("Fitur belum diimplementasikan."); }
            else { MessageBox.Show("Pilih tabel terlebih dahulu."); }
        }

        /// <summary>
        /// Delete selected row
        /// </summary>
        public void deleteRow()
        {
            Log Log = new Log();
            _log l;
            List<_log> list = new List<_log>();

            Int32 selectedCellCount = dataGridView1.GetCellCount(DataGridViewElementStates.Selected);

            if (selectedCellCount > 0)
            {
                if (Equals(node.Tag, "_user"))
                {
                    _userTableAdapter f = new _userTableAdapter();
                    if (MessageBox.Show("Hapus record yang dipilih?", "Konfirmasi", MessageBoxButtons.OKCancel) == DialogResult.OK)
                    {
                        try
                        {
                            foreach (DataGridViewRow row in dataGridView1.SelectedRows)
                            {
                                f.DeleteQuery(Convert.ToInt32(dataGridView1[0, row.Index].Value));
                                l = new _log("_user", Convert.ToInt32(dataGridView1[0, row.Index].Value), "", "delete","","");
                                list.Add(l);
                                dataGridView1.Rows.Remove(row);
                            }
                        }
                        catch (Exception msg) { MessageBox.Show("Penghapusan record tidak berhasil, sistem tidak dapat terkoneksi ke database."); }
                    }
                }
                else if (Equals(node.Tag, "agama"))
                {
                    agamaTableAdapter f = new agamaTableAdapter();
                    if (MessageBox.Show("Hapus record yang dipilih?", "Konfirmasi", MessageBoxButtons.OKCancel) == DialogResult.OK)
                    {
                        try
                        {
                            foreach (DataGridViewRow row in dataGridView1.SelectedRows)
                            {
                                f.DeleteQuery(Convert.ToInt32(dataGridView1[0, row.Index].Value));
                                l = new _log("agama", Convert.ToInt32(dataGridView1[0, row.Index].Value), "", "delete", "", "");
                                list.Add(l);
                                dataGridView1.Rows.Remove(row);
                            }
                        }
                        catch (Exception msg) { MessageBox.Show("Penghapusan record tidak berhasil, sistem tidak dapat terkoneksi ke database."); }
                    }
                }
                else if (Equals(node.Tag, "aset"))
                {
                    asetTableAdapter f = new asetTableAdapter();
                    if (MessageBox.Show("Hapus record yang dipilih?", "Konfirmasi", MessageBoxButtons.OKCancel) == DialogResult.OK)
                    {
                        try
                        {
                            foreach (DataGridViewRow row in dataGridView1.SelectedRows)
                            {
                                f.DeleteQuery(Convert.ToInt32(dataGridView1[0, row.Index].Value));
                                l = new _log("aset", Convert.ToInt32(dataGridView1[0, row.Index].Value), "", "delete", "", "");
                                list.Add(l);
                                dataGridView1.Rows.Remove(row);
                            }
                        }
                        catch (Exception msg) { MessageBox.Show("Penghapusan record tidak berhasil, sistem tidak dapat terkoneksi ke database."); }
                    }
                }
                else if (Equals(node.Tag, "cabang"))
                {
                    cabangTableAdapter f = new cabangTableAdapter();
                    if (MessageBox.Show("Hapus record yang dipilih?", "Konfirmasi", MessageBoxButtons.OKCancel) == DialogResult.OK)
                    {
                        try
                        {
                            foreach (DataGridViewRow row in dataGridView1.SelectedRows)
                            {
                                f.DeleteQuery(Convert.ToInt32(dataGridView1[0, row.Index].Value));
                                l = new _log("cabang", Convert.ToInt32(dataGridView1[0, row.Index].Value), "", "delete", "", "");
                                list.Add(l);
                                dataGridView1.Rows.Remove(row);
                            }
                        }
                        catch (Exception msg) { MessageBox.Show("Penghapusan record tidak berhasil, sistem tidak dapat terkoneksi ke database."); }
                    }
                }
                else if (Equals(node.Tag, "free_gift"))
                {
                    free_giftTableAdapter f = new free_giftTableAdapter();
                    if (MessageBox.Show("Hapus record yang dipilih?", "Konfirmasi", MessageBoxButtons.OKCancel) == DialogResult.OK)
                    {
                        try
                        {
                            foreach (DataGridViewRow row in dataGridView1.SelectedRows)
                            {
                                f.DeleteQuery(Convert.ToInt32(dataGridView1[0, row.Index].Value));
                                l = new _log("free_gift", Convert.ToInt32(dataGridView1[0, row.Index].Value), "", "delete", "", "");
                                list.Add(l);
                                dataGridView1.Rows.Remove(row);
                            }
                        }
                        catch (Exception msg) { MessageBox.Show("Penghapusan record tidak berhasil, sistem tidak dapat terkoneksi ke database."); }
                    }
                }
                else if (Equals(node.Tag, "golongan_darah"))
                {
                    golongan_darahTableAdapter f = new golongan_darahTableAdapter();
                    if (MessageBox.Show("Hapus record yang dipilih?", "Konfirmasi", MessageBoxButtons.OKCancel) == DialogResult.OK)
                    {
                        try
                        {
                            foreach (DataGridViewRow row in dataGridView1.SelectedRows)
                            {
                                f.DeleteQuery(Convert.ToInt32(dataGridView1[0, row.Index].Value));
                                l = new _log("golongan_darah", Convert.ToInt32(dataGridView1[0, row.Index].Value), "", "delete", "", "");
                                list.Add(l);
                                dataGridView1.Rows.Remove(row);
                            }
                        }
                        catch (Exception msg) { MessageBox.Show("Penghapusan record tidak berhasil, sistem tidak dapat terkoneksi ke database."); }
                    }
                }
                else if (Equals(node.Tag, "jenis_aset"))
                {
                    jenis_asetTableAdapter f = new jenis_asetTableAdapter();
                    if (MessageBox.Show("Hapus record yang dipilih?", "Konfirmasi", MessageBoxButtons.OKCancel) == DialogResult.OK)
                    {
                        try
                        {
                            foreach (DataGridViewRow row in dataGridView1.SelectedRows)
                            {
                                f.DeleteQuery(Convert.ToInt32(dataGridView1[0, row.Index].Value));
                                l = new _log("jenis_aset", Convert.ToInt32(dataGridView1[0, row.Index].Value), "", "delete", "", "");
                                list.Add(l);
                                dataGridView1.Rows.Remove(row);
                            }
                        }
                        catch (Exception msg) { MessageBox.Show("Penghapusan record tidak berhasil, sistem tidak dapat terkoneksi ke database."); }
                    }
                }
                else if (Equals(node.Tag, "jenis_stok"))
                {
                    jenis_stokTableAdapter f = new jenis_stokTableAdapter();
                    if (MessageBox.Show("Hapus record yang dipilih?", "Konfirmasi", MessageBoxButtons.OKCancel) == DialogResult.OK)
                    {
                        try
                        {
                            foreach (DataGridViewRow row in dataGridView1.SelectedRows)
                            {
                                f.DeleteQuery(Convert.ToInt32(dataGridView1[0, row.Index].Value));
                                l = new _log("jenis_stok", Convert.ToInt32(dataGridView1[0, row.Index].Value), "", "delete", "", "");
                                list.Add(l);
                                dataGridView1.Rows.Remove(row);
                            }
                        }
                        catch (Exception msg) { MessageBox.Show("Penghapusan record tidak berhasil, sistem tidak dapat terkoneksi ke database."); }
                    }
                }
                else if (Equals(node.Tag, "karyawan"))
                {
                    karyawanTableAdapter f = new karyawanTableAdapter();
                    if (MessageBox.Show("Hapus record yang dipilih?", "Konfirmasi", MessageBoxButtons.OKCancel) == DialogResult.OK)
                    {
                        try
                        {
                            foreach (DataGridViewRow row in dataGridView1.SelectedRows)
                            {
                                f.DeleteQuery(Convert.ToInt32(dataGridView1[0, row.Index].Value));
                                l = new _log("karyawan", Convert.ToInt32(dataGridView1[0, row.Index].Value), "", "delete", "", "");
                                list.Add(l);
                                dataGridView1.Rows.Remove(row);
                            }
                        }
                        catch (Exception msg) { MessageBox.Show("Penghapusan record tidak berhasil, sistem tidak dapat terkoneksi ke database."); }
                    }
                }
                else if (Equals(node.Tag, "keahlian"))
                {
                    keahlianTableAdapter f = new keahlianTableAdapter();
                    if (MessageBox.Show("Hapus record yang dipilih?", "Konfirmasi", MessageBoxButtons.OKCancel) == DialogResult.OK)
                    {
                        try
                        {
                            foreach (DataGridViewRow row in dataGridView1.SelectedRows)
                            {
                                f.DeleteQuery(Convert.ToInt32(dataGridView1[0, row.Index].Value));
                                l = new _log("keahlian", Convert.ToInt32(dataGridView1[0, row.Index].Value), "", "delete", "", "");
                                list.Add(l);
                                dataGridView1.Rows.Remove(row);
                            }
                        }
                        catch (Exception msg) { MessageBox.Show("Penghapusan record tidak berhasil, sistem tidak dapat terkoneksi ke database."); }
                    }
                }
                else if (Equals(node.Tag, "komisi_layanan"))
                {
                    komisi_layananTableAdapter f = new komisi_layananTableAdapter();
                    if (MessageBox.Show("Hapus record yang dipilih?", "Konfirmasi", MessageBoxButtons.OKCancel) == DialogResult.OK)
                    {
                        try
                        {
                            foreach (DataGridViewRow row in dataGridView1.SelectedRows)
                            {
                                f.DeleteQuery(Convert.ToInt32(dataGridView1[0, row.Index].Value));
                                l = new _log("komisi_layanan", Convert.ToInt32(dataGridView1[0, row.Index].Value), "", "delete", "", "");
                                list.Add(l);
                                dataGridView1.Rows.Remove(row);
                            }
                        }
                        catch (Exception msg) { MessageBox.Show("Penghapusan record tidak berhasil, sistem tidak dapat terkoneksi ke database."); }
                    }
                }
                else if (Equals(node.Tag, "konsumen"))
                {
                    konsumenTableAdapter f = new konsumenTableAdapter();
                    if (MessageBox.Show("Hapus record yang dipilih?", "Konfirmasi", MessageBoxButtons.OKCancel) == DialogResult.OK)
                    {
                        try
                        {
                            foreach (DataGridViewRow row in dataGridView1.SelectedRows)
                            {
                                f.DeleteQuery(Convert.ToInt32(dataGridView1[0, row.Index].Value));
                                l = new _log("konsumen", Convert.ToInt32(dataGridView1[0, row.Index].Value), "", "delete", "", "");
                                list.Add(l);
                                dataGridView1.Rows.Remove(row);
                            }
                        }
                        catch (Exception msg) { MessageBox.Show("Penghapusan record tidak berhasil, sistem tidak dapat terkoneksi ke database."); }
                    }
                }
                else if (Equals(node.Tag, "layanan"))
                {
                    layananTableAdapter f = new layananTableAdapter();
                    if (MessageBox.Show("Hapus record yang dipilih?", "Konfirmasi", MessageBoxButtons.OKCancel) == DialogResult.OK)
                    {
                        try
                        {
                            foreach (DataGridViewRow row in dataGridView1.SelectedRows)
                            {
                                f.DeleteQuery(Convert.ToInt32(dataGridView1[0, row.Index].Value));
                                l = new _log("layanan", Convert.ToInt32(dataGridView1[0, row.Index].Value), "", "delete", "", "");
                                list.Add(l);
                                dataGridView1.Rows.Remove(row);
                            }
                        }
                        catch (Exception msg) { MessageBox.Show("Penghapusan record tidak berhasil, sistem tidak dapat terkoneksi ke database."); }
                    }
                }
                else if (Equals(node.Tag, "layanan_cabang"))
                {
                    layanan_cabangTableAdapter f = new layanan_cabangTableAdapter();
                    if (MessageBox.Show("Hapus record yang dipilih?", "Konfirmasi", MessageBoxButtons.OKCancel) == DialogResult.OK)
                    {
                        try
                        {
                            foreach (DataGridViewRow row in dataGridView1.SelectedRows)
                            {
                                f.DeleteQuery(Convert.ToInt32(dataGridView1[0, row.Index].Value));
                                l = new _log("layanan_cabang", Convert.ToInt32(dataGridView1[0, row.Index].Value), "", "delete", "", "");
                                list.Add(l);
                                dataGridView1.Rows.Remove(row);
                            }
                        }
                        catch (Exception msg) { MessageBox.Show("Penghapusan record tidak berhasil, sistem tidak dapat terkoneksi ke database."); }
                    }
                }
                else if (Equals(node.Tag, "metode_pembayaran"))
                {
                    metode_pembayaranTableAdapter f = new metode_pembayaranTableAdapter();
                    if (MessageBox.Show("Hapus record yang dipilih?", "Konfirmasi", MessageBoxButtons.OKCancel) == DialogResult.OK)
                    {
                        try
                        {
                            foreach (DataGridViewRow row in dataGridView1.SelectedRows)
                            {
                                f.DeleteQuery(Convert.ToInt32(dataGridView1[0, row.Index].Value));
                                l = new _log("metode_pembayaran", Convert.ToInt32(dataGridView1[0, row.Index].Value), "", "delete", "", "");
                                list.Add(l);
                                dataGridView1.Rows.Remove(row);
                            }
                        }
                        catch (Exception msg) { MessageBox.Show("Penghapusan record tidak berhasil, sistem tidak dapat terkoneksi ke database."); }
                    }
                }
                else if (Equals(node.Tag, "preferensi_karyawan"))
                {
                    preferensi_karyawanTableAdapter f = new preferensi_karyawanTableAdapter();
                    if (MessageBox.Show("Hapus record yang dipilih?", "Konfirmasi", MessageBoxButtons.OKCancel) == DialogResult.OK)
                    {
                        try
                        {
                            foreach (DataGridViewRow row in dataGridView1.SelectedRows)
                            {
                                f.DeleteQuery(Convert.ToInt32(dataGridView1[0, row.Index].Value));
                                l = new _log("preferensi_karyawan", Convert.ToInt32(dataGridView1[0, row.Index].Value), "", "delete", "", "");
                                list.Add(l);
                                dataGridView1.Rows.Remove(row);
                            }
                        }
                        catch (Exception msg) { MessageBox.Show("Penghapusan record tidak berhasil, sistem tidak dapat terkoneksi ke database."); }
                    }
                }
                else if (Equals(node.Tag, "produk_cabang"))
                {
                    produk_cabangTableAdapter f = new produk_cabangTableAdapter();
                    if (MessageBox.Show("Hapus record yang dipilih?", "Konfirmasi", MessageBoxButtons.OKCancel) == DialogResult.OK)
                    {
                        try
                        {
                            foreach (DataGridViewRow row in dataGridView1.SelectedRows)
                            {
                                f.DeleteQuery(Convert.ToInt32(dataGridView1[0, row.Index].Value));
                                l = new _log("produk_cabang", Convert.ToInt32(dataGridView1[0, row.Index].Value), "", "delete", "", "");
                                list.Add(l);
                                dataGridView1.Rows.Remove(row);
                            }
                        }
                        catch (Exception msg) { MessageBox.Show("Penghapusan record tidak berhasil, sistem tidak dapat terkoneksi ke database."); }
                    }
                }
                else if (Equals(node.Tag, "promo"))
                {
                    promoTableAdapter f = new promoTableAdapter();
                    if (MessageBox.Show("Hapus record yang dipilih?", "Konfirmasi", MessageBoxButtons.OKCancel) == DialogResult.OK)
                    {
                        try
                        {
                            foreach (DataGridViewRow row in dataGridView1.SelectedRows)
                            {
                                f.DeleteQuery(Convert.ToInt32(dataGridView1[0, row.Index].Value));
                                l = new _log("promo", Convert.ToInt32(dataGridView1[0, row.Index].Value), "", "delete", "", "");
                                list.Add(l);
                                dataGridView1.Rows.Remove(row);
                            }
                        }
                        catch (Exception msg) { MessageBox.Show("Penghapusan record tidak berhasil, sistem tidak dapat terkoneksi ke database."); }
                    }
                }
                else if (Equals(node.Tag, "role"))
                {
                    roleTableAdapter f = new roleTableAdapter();
                    if (MessageBox.Show("Hapus record yang dipilih?", "Konfirmasi", MessageBoxButtons.OKCancel) == DialogResult.OK)
                    {
                        try
                        {
                            foreach (DataGridViewRow row in dataGridView1.SelectedRows)
                            {
                                f.DeleteQuery(Convert.ToInt32(dataGridView1[0, row.Index].Value));
                                l = new _log("role", Convert.ToInt32(dataGridView1[0, row.Index].Value), "", "delete", "", "");
                                list.Add(l);
                                dataGridView1.Rows.Remove(row);
                            }
                        }
                        catch (Exception msg) { MessageBox.Show("Penghapusan record tidak berhasil, sistem tidak dapat terkoneksi ke database."); }
                    }
                }
                else if (Equals(node.Tag, "server_log"))
                {
                    server_logTableAdapter f = new server_logTableAdapter();
                    if (MessageBox.Show("Hapus record yang dipilih?", "Konfirmasi", MessageBoxButtons.OKCancel) == DialogResult.OK)
                    {
                        try
                        {
                            foreach (DataGridViewRow row in dataGridView1.SelectedRows)
                            {
                                f.DeleteQuery(Convert.ToInt32(dataGridView1[0, row.Index].Value));
                                l = new _log("server_log", Convert.ToInt32(dataGridView1[0, row.Index].Value), "", "delete", "", "");
                                list.Add(l);
                                dataGridView1.Rows.Remove(row);
                            }
                        }
                        catch (Exception msg) { MessageBox.Show("Penghapusan record tidak berhasil, sistem tidak dapat terkoneksi ke database."); }
                    }
                }
                else if (Equals(node.Tag, "status"))
                {
                    statusTableAdapter f = new statusTableAdapter();
                    if (MessageBox.Show("Hapus record yang dipilih?", "Konfirmasi", MessageBoxButtons.OKCancel) == DialogResult.OK)
                    {
                        try
                        {
                            foreach (DataGridViewRow row in dataGridView1.SelectedRows)
                            {
                                f.DeleteQuery(Convert.ToInt32(dataGridView1[0, row.Index].Value));
                                l = new _log("status", Convert.ToInt32(dataGridView1[0, row.Index].Value), "", "delete", "", "");
                                list.Add(l);
                                dataGridView1.Rows.Remove(row);
                            }
                        }
                        catch (Exception msg) { MessageBox.Show("Penghapusan record tidak berhasil, sistem tidak dapat terkoneksi ke database."); }
                    }
                }
                else if (Equals(node.Tag, "stok"))
                {
                    stokTableAdapter f = new stokTableAdapter();
                    if (MessageBox.Show("Hapus record yang dipilih?", "Konfirmasi", MessageBoxButtons.OKCancel) == DialogResult.OK)
                    {
                        try
                        {
                            foreach (DataGridViewRow row in dataGridView1.SelectedRows)
                            {
                                f.DeleteQuery(Convert.ToInt32(dataGridView1[0, row.Index].Value));
                                l = new _log("stok", Convert.ToInt32(dataGridView1[0, row.Index].Value), "", "delete", "", "");
                                list.Add(l);
                                dataGridView1.Rows.Remove(row);
                            }
                        }
                        catch (Exception msg) { MessageBox.Show("Penghapusan record tidak berhasil, sistem tidak dapat terkoneksi ke database."); }
                    }
                }
                else if (Equals(node.Tag, "transaksi"))
                {
                    transaksiTableAdapter f = new transaksiTableAdapter();
                    if (MessageBox.Show("Hapus record yang dipilih?", "Konfirmasi", MessageBoxButtons.OKCancel) == DialogResult.OK)
                    {
                        try
                        {
                            foreach (DataGridViewRow row in dataGridView1.SelectedRows)
                            {
                                f.DeleteQuery(Convert.ToInt32(dataGridView1[0, row.Index].Value));
                                l = new _log("transaksi", Convert.ToInt32(dataGridView1[0, row.Index].Value), "", "delete", "", "");
                                list.Add(l);
                                dataGridView1.Rows.Remove(row);
                            }
                        }
                        catch (Exception msg) { MessageBox.Show("Penghapusan record tidak berhasil, sistem tidak dapat terkoneksi ke database."); }
                    }
                }
                else if (Equals(node.Tag, "transaksi_layanan"))
                {
                    transaksi_layananTableAdapter f = new transaksi_layananTableAdapter();
                    if (MessageBox.Show("Hapus record yang dipilih?", "Konfirmasi", MessageBoxButtons.OKCancel) == DialogResult.OK)
                    {
                        try
                        {
                            foreach (DataGridViewRow row in dataGridView1.SelectedRows)
                            {
                                f.DeleteQuery(Convert.ToInt32(dataGridView1[0, row.Index].Value));
                                l = new _log("transaksi_layanan", Convert.ToInt32(dataGridView1[0, row.Index].Value), "", "delete", "", "");
                                list.Add(l);
                                dataGridView1.Rows.Remove(row);
                            }
                        }
                        catch (Exception msg) { MessageBox.Show("Penghapusan record tidak berhasil, sistem tidak dapat terkoneksi ke database."); }
                    }
                }
                else if (Equals(node.Tag, "transaksi_pembayaran"))
                {
                    transaksi_pembayaranTableAdapter f = new transaksi_pembayaranTableAdapter();
                    if (MessageBox.Show("Hapus record yang dipilih?", "Konfirmasi", MessageBoxButtons.OKCancel) == DialogResult.OK)
                    {
                        try
                        {
                            foreach (DataGridViewRow row in dataGridView1.SelectedRows)
                            {
                                f.DeleteQuery(Convert.ToInt32(dataGridView1[0, row.Index].Value));
                                l = new _log("transaksi_pembayaran", Convert.ToInt32(dataGridView1[0, row.Index].Value), "", "delete", "", "");
                                list.Add(l);
                                dataGridView1.Rows.Remove(row);
                            }
                        }
                        catch (Exception msg) { MessageBox.Show("Penghapusan record tidak berhasil, sistem tidak dapat terkoneksi ke database."); }
                    }
                }
                else if (Equals(node.Tag, "transaksi_produk"))
                {
                    transaksi_produkTableAdapter f = new transaksi_produkTableAdapter();
                    if (MessageBox.Show("Hapus record yang dipilih?", "Konfirmasi", MessageBoxButtons.OKCancel) == DialogResult.OK)
                    {
                        try
                        {
                            foreach (DataGridViewRow row in dataGridView1.SelectedRows)
                            {
                                f.DeleteQuery(Convert.ToInt32(dataGridView1[0, row.Index].Value));
                                l = new _log("transaksi_produk", Convert.ToInt32(dataGridView1[0, row.Index].Value), "", "delete", "", "");
                                list.Add(l);
                                dataGridView1.Rows.Remove(row);
                            }
                        }
                        catch (Exception msg) { MessageBox.Show("Penghapusan record tidak berhasil, sistem tidak dapat terkoneksi ke database."); }
                    }
                }
                Log.ProcessLog(list);
            }
        }

        /// <summary>
        /// function for helping refresh datagrid
        /// </summary>
        public void PerformRefresh()
        {
            this.treeView1_AfterSelect(null, null);
        }

        /// <summary>
        /// Rebuild treeview to comply to updated connectionString
        /// </summary>
        public void Regenerate()
        {
            switch (User.roleid)
            {
                case 4: // Owner
                    karyawan = treeView1.Nodes.Add("Karyawan");
                    karyawan.Nodes.Add(node11); karyawan.Nodes.Add(node08); karyawan.Nodes.Add(node09); karyawan.Nodes.Add(node15);
                    cabang = treeView1.Nodes.Add("Cabang");
                    cabang.Nodes.Add(node03); cabang.Nodes.Add(node12); cabang.Nodes.Add(node10); cabang.Nodes.Add(node13); cabang.Nodes.Add(node16);
                    transaksi = treeView1.Nodes.Add("Transaksi");
                    transaksi.Nodes.Add(node22); transaksi.Nodes.Add(node23); transaksi.Nodes.Add(node24); transaksi.Nodes.Add(node25); transaksi.Nodes.Add(node14); transaksi.Nodes.Add(node17); transaksi.Nodes.Add(node04);
                    asetstok = treeView1.Nodes.Add("Aset & Stok");
                    asetstok.Nodes.Add(node02); asetstok.Nodes.Add(node06); asetstok.Nodes.Add(node21); asetstok.Nodes.Add(node07);
                    break;
                case 3: // Manajemen
                    karyawan = treeView1.Nodes.Add("Karyawan");
                    karyawan.Nodes.Add(node11); karyawan.Nodes.Add(node08); karyawan.Nodes.Add(node09); karyawan.Nodes.Add(node15);
                    cabang = treeView1.Nodes.Add("Cabang");
                    cabang.Nodes.Add(node03); cabang.Nodes.Add(node12); cabang.Nodes.Add(node10); cabang.Nodes.Add(node13); cabang.Nodes.Add(node16);
                    transaksi = treeView1.Nodes.Add("Transaksi");
                    transaksi.Nodes.Add(node22); transaksi.Nodes.Add(node23); transaksi.Nodes.Add(node24); transaksi.Nodes.Add(node25); transaksi.Nodes.Add(node14); transaksi.Nodes.Add(node17); transaksi.Nodes.Add(node04);
                    asetstok = treeView1.Nodes.Add("Aset & Stok");
                    asetstok.Nodes.Add(node02); asetstok.Nodes.Add(node06); asetstok.Nodes.Add(node21); asetstok.Nodes.Add(node07);
                    break;
                case 2: // Supervisor
                    administratif = treeView1.Nodes.Add("Administratif");
                    administratif.Nodes.Add(node00); administratif.Nodes.Add(node18); administratif.Nodes.Add(node19);
                    karyawan = treeView1.Nodes.Add("Karyawan");
                    karyawan.Nodes.Add(node11); karyawan.Nodes.Add(node08); karyawan.Nodes.Add(node09); karyawan.Nodes.Add(node15);
                    cabang = treeView1.Nodes.Add("Cabang");
                    cabang.Nodes.Add(node03); cabang.Nodes.Add(node12); cabang.Nodes.Add(node10); cabang.Nodes.Add(node13); cabang.Nodes.Add(node16);
                    asetstok = treeView1.Nodes.Add("Aset & Stok");
                    asetstok.Nodes.Add(node02); asetstok.Nodes.Add(node06); asetstok.Nodes.Add(node21); asetstok.Nodes.Add(node07);
                    lainnya = treeView1.Nodes.Add("Lainnya");
                    lainnya.Nodes.Add(node01); lainnya.Nodes.Add(node05); lainnya.Nodes.Add(node20);
                    break;
                default: // Kasir (baseline)
                    transaksi = treeView1.Nodes.Add("Transaksi");
                    transaksi.Nodes.Add(node22); transaksi.Nodes.Add(node23); transaksi.Nodes.Add(node24); transaksi.Nodes.Add(node25); transaksi.Nodes.Add(node14); transaksi.Nodes.Add(node17); transaksi.Nodes.Add(node04);
                    break;
            }
        }

        /// <summary>
        /// Showing dabatase configuration dialogue
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void databaseSettingToolStripMenuItem_Click(object sender, EventArgs e)
        { DatabaseConfigurationForm f = new DatabaseConfigurationForm(this); f.Show(); }

        private void button4_Click(object sender, EventArgs e)
        {
            if (!textBox1.Text.Equals("") && !textBox2.Text.Equals(""))
            {
                _userTableAdapter user = new _userTableAdapter();
                AnataServerDataSet._userDataTable dt = new AnataServerDataSet._userDataTable();

                dt = user.isUser(textBox1.Text, textBox2.Text);

                if (dt.Count == 1)
                {
                    DataRowCollection dr = dt.Rows;
                    DataRow drow = dr[0];

                    User.username = drow[dt.usernameColumn].ToString();
                    User.userid = Convert.ToInt32(drow[dt.id_karyawanColumn]);
                    User.roleid = Convert.ToInt32(drow[dt.id_roleColumn]);
                    panel1.Hide();
                    splitContainer1.Panel1.Enabled = true;
                    logOutToolStripMenuItem.Enabled = true;
                    Regenerate();
                    toolStripStatusLabel1.Text = "Welcome " + User.username;
                }
                else MessageBox.Show("Username dan password yang Anda masukan salah atau tidak terdaftar");
            }
            else
            {
                MessageBox.Show("Masukkan Username dan Password Anda.");
            }
        }

        private void logOutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            switch (User.roleid)
            {
                case 4:
                    treeView1.Nodes.Remove(karyawan);
                    treeView1.Nodes.Remove(cabang);
                    treeView1.Nodes.Remove(asetstok);
                    treeView1.Nodes.Remove(transaksi);
                    break;
                case 3:
                    treeView1.Nodes.Remove(karyawan);
                    treeView1.Nodes.Remove(cabang);
                    treeView1.Nodes.Remove(transaksi);
                    treeView1.Nodes.Remove(asetstok);
                    break;
                case 2:
                    treeView1.Nodes.Remove(administratif);
                    treeView1.Nodes.Remove(karyawan);
                    treeView1.Nodes.Remove(cabang);
                    treeView1.Nodes.Remove(asetstok);
                    treeView1.Nodes.Remove(lainnya);
                    break;
                default:
                    treeView1.Nodes.Remove(transaksi);
                    break;
            }
            dataGridView1.DataSource = null;
            button1.Enabled = false;
            button2.Enabled = false;
            button3.Enabled = false;
            logOutToolStripMenuItem.Enabled = false;
            splitContainer1.Panel1.Enabled = false;
            panel1.Show();
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }
    }
}
